package com.clx.utils;

import com.clx.domain.entity.Article;
import com.clx.domain.vo.HotArticleVo;
import org.springframework.beans.BeanUtils;

import java.sql.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class BeanCopyUtils {
    public static <V> V copyBean(Object source, Class<V> clazz) {
        V result = null;
        try {
            result = clazz.newInstance();
            BeanUtils.copyProperties(source, result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;

    }

    public static <V, O> List<V> copyBeanList(List<O> list, Class<V> clazz) {
        return list.stream().map(o->copyBean(o, clazz)).collect(Collectors.toList());
    }
}
